home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / etc / init.d / bluetooth < prev    next >
Text File  |  2008-10-26  |  5KB  |  202 lines

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: bluetooth
  4. # Required-Start:    $local_fs $syslog $remote_fs dbus
  5. # Required-Stop:     $local_fs $syslog $remote_fs
  6. # Default-Start:     2 3 4 5
  7. # Default-Stop:      0 1 6
  8. # Short-Description: Start bluetooth daemons
  9. ### END INIT INFO
  10. #
  11. # bluez    Bluetooth subsystem starting and stopping
  12. #
  13. # originally from bluez's scripts/bluetooth.init
  14. #
  15. # Edd Dumbill <ejad@debian.org>
  16. # LSB 3.0 compilance and enhancements by Filippo Giunchedi <filippo@debian.org>
  17. #
  18. # Updated for bluez 4.7 by Mario Limonciello <mario_limonciello@dell.com>
  19. #
  20. # startup control over dund and pand can be changed by editing
  21. # /etc/default/bluetooth
  22.  
  23. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  24. DESC=bluetooth
  25.  
  26. DAEMON=/usr/sbin/bluetoothd
  27. HCIATTACH=/usr/sbin/hciattach
  28.  
  29. HID2HCI=/usr/sbin/hid2hci
  30. HID2HCI_ENABLED=1
  31. HID2HCI_UNDO=1
  32.  
  33. UART_CONF=/etc/bluetooth/uart
  34.  
  35. RFCOMM=/usr/bin/rfcomm
  36. RFCOMM_NAME=rfcomm
  37. RFCOMM_CONF=/etc/bluetooth/rfcomm.conf
  38. SDPTOOL=/usr/bin/sdptool
  39.  
  40. test -f /etc/default/bluetooth && . /etc/default/bluetooth
  41. test -f /etc/default/rcS && . /etc/default/rcS
  42.  
  43. . /lib/lsb/init-functions
  44.  
  45. set -e
  46.  
  47. run_sdptool()
  48. {
  49.     test -x $SDPTOOL || return 1
  50.  
  51.     if ! test -z "$SDPTOOL_OPTIONS" ; then
  52.         oldifs="$IFS"
  53.         IFS=";"
  54.         for o in $SDPTOOL_OPTIONS ; do
  55.             #echo "execing $SDPTOOL $o"
  56.             IFS=" "
  57.             if [ "$VERBOSE" != "no" ]; then
  58.                 $SDPTOOL $o
  59.             else
  60.                 $SDPTOOL $o >/dev/null 2>&1
  61.             fi
  62.         done
  63.         IFS="$oldifs"
  64.     fi
  65.  
  66. }
  67.  
  68. enable_hci_input()
  69. {
  70.        if [ "$VERBOSE" != no ]; then
  71.                log_progress_msg "hid_devices"
  72.                $HID2HCI --tohci
  73.        else
  74.                $HID2HCI --tohci >/dev/null 2>&1
  75.        fi
  76. }
  77.  
  78. disable_hci_input()
  79. {
  80.        if [ "$VERBOSE" != no ]; then
  81.                log_progress_msg "hid_devices"
  82.                $HID2HCI --tohid
  83.        else
  84.                $HID2HCI --tohid >/dev/null 2>&1
  85.        fi
  86. }
  87.  
  88. start_uarts()
  89. {
  90.     [ -f $HCIATTACH ] && [ -f $UART_CONF ] || return
  91.     grep -v '^#' $UART_CONF | while read i; do
  92.                if [ "$VERBOSE" != no ]; then
  93.                        $HCIATTACH $i
  94.                else
  95.                        $HCIATTACH $i >/dev/null 2>&1
  96.                fi
  97.     done
  98. }
  99.  
  100. stop_uarts()
  101. {
  102.     killall hciattach > /dev/null 2>&1 || true
  103. }
  104.  
  105. start_rfcomm()
  106. {
  107.     if [ -x $RFCOMM ] && [ -f $RFCOMM_CONF ] ; then
  108.         # rfcomm must always succeed for now: users
  109.         # may not yet have an rfcomm-enabled kernel
  110.                 if [ "$VERBOSE" != no ]; then
  111.                        log_progress_msg "rfcomm"
  112.                        $RFCOMM -f $RFCOMM_CONF bind all || true
  113.                 else
  114.                        $RFCOMM -f $RFCOMM_CONF bind all >/dev/null 2>&1 || true
  115.                 fi
  116.     fi
  117. }
  118.  
  119. stop_rfcomm()
  120. {
  121.     if [ -x $RFCOMM ] ; then
  122.                if [ "$VERBOSE" != no ]; then
  123.                        log_progress_msg "rfcomm"
  124.                        $RFCOMM unbind all || true
  125.                else
  126.                        $RFCOMM unbind all >/dev/null 2>&1 || true
  127.                fi
  128.     fi
  129. }
  130.  
  131. restart_rfcomm()
  132. {
  133.     if [ -x $RFCOMM ] && [ -f $RFCOMM_CONF ] ; then
  134.                if [ "$VERBOSE" != no ]; then
  135.                        log_progress_msg  "rfcomm"
  136.                        $RFCOMM unbind all || true
  137.                        $RFCOMM -f $RFCOMM_CONF bind all || true
  138.                else
  139.                        $RFCOMM unbind all >/dev/null 2>&1|| true
  140.                        $RFCOMM -f $RFCOMM_CONF bind all >/dev/null 2>&1 || true
  141.                fi
  142.     fi
  143. }
  144.  
  145. case "$1" in
  146.   start)
  147.     log_daemon_msg "Starting $DESC"
  148.  
  149.     if test "$BLUETOOTH_ENABLED" = "0"; then
  150.         log_progress_msg "disabled. see /etc/default/bluetooth"
  151.         log_end_msg 0
  152.         exit 0
  153.     fi
  154.  
  155.     start-stop-daemon --start --quiet --exec $DAEMON || true
  156.     log_progress_msg "bluetoothd"
  157.  
  158.     run_sdptool || true
  159.  
  160.     start_uarts || true
  161.  
  162.     if test "$HID2HCI_ENABLED" = "1"; then
  163.         enable_hci_input || true
  164.     fi
  165.     start_rfcomm || true
  166.     log_end_msg 0
  167.     ;;
  168.   stop)
  169.     log_daemon_msg "Stopping $DESC"
  170.     if test "$BLUETOOTH_ENABLED" = "0"; then
  171.         log_progress_msg "disabled."
  172.         log_end_msg 0
  173.         exit 0
  174.     fi
  175.     stop_rfcomm || true
  176.     if test "$HID2HCI_UNDO" = "1"; then
  177.         disable_hci_input || true
  178.     fi
  179.     start-stop-daemon --stop --quiet --exec $DAEMON || true
  180.     log_progress_msg "bluetoothd"
  181.     stop_uarts || true
  182.     log_end_msg 0
  183.     ;;
  184.   restart|force-reload)
  185.     $0 stop
  186.     $0 start
  187.     ;;
  188.   status)
  189.     status_of_proc "$DAEMON" "$DESC" && exit 0 || exit $?
  190.     ;;
  191.   *)
  192.     N=/etc/init.d/bluetooth
  193.     # echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
  194.     echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
  195.     exit 1
  196.     ;;
  197. esac
  198.  
  199. exit 0
  200.  
  201. # vim:noet
  202.